const { read, write } = require('../lib/read&write')

const REPORTURL = '../data/report.json'
function setReport(report) {
  const __Report = read(REPORTURL)
  __Report.push(report)
  write(__Report, REPORTURL)
}

function editReport(report) {
  const __Reprts = read(REPORTURL)
  __Reprts.splice(
    __Reprts.findIndex((item) => item.id === report.id),
    1,
    report
  )
  write(__Reprts, REPORTURL)
}

function getAllReports() {
  const __Report = read(REPORTURL)
  return __Report
}

function searchReport(reportId) {
  const __Report = read(REPORTURL)
  return __Report.find((item) => item.id === reportId)
}

module.exports = {
  searchReport,
  getAllReports,
  setReport,
  // 以下未用
  editReport
}